var Room=require("../Model/Room.js");
function RoomControll(app,Mysql)
{
	var RoomModel=Object.create(Room.RoomModel);
	app.post('/room/updatecleanroom', UpdateCleanRoom);
	app.post('/room/updateroomstat', UpdateRoomStat);
	app.get('/room/getavailableroom', GetAvailableRoom);

	function UpdateCleanRoom(req, res, next) {
		var Code=req.body.code;
		RoomModel.UpdateCleanRoom(Mysql,Code,function(Rst)
		{
			var SR={iRst:Rst};
			res.json(SR);
		});
	}

	function GetAvailableRoom(req, res, next){
		//console.log("GetAvailableRoom params:"+JSON.stringify(req.params));
		var Code=req.query.code;
		var TypeId=req.query.typeid;
		var DateFr=req.query.datefr;
		var DateTo=req.query.dateto;
		RoomModel.GetAvailableRoom(Mysql,Code,TypeId,DateFr,DateTo,function(Data)
		{
			res.json(Data);
		});
	}

	function UpdateRoomStat(req, res, next){
		var RoomId=req.body.roomid;
		var StatJson=req.body.stat;
		var KeyValueArr=eval(StatJson);
		RoomModel.UpdateRoomStat(Mysql,RoomId,KeyValueArr,function(Rst){
			var SR={iRst:Rst};
			res.json(SR);
		});
	}

}
exports.RoomControll=RoomControll;